import request from '@/utils/request'
import type { LoginForm, LoginResponse, UserInfoResponse, CaptchaResponse } from '@/types/user'

/**
 * 登录
 */
export function login(data: LoginForm) {
  return request.post<LoginResponse>('/auth/login', {
    username: data.username,
    password: data.password,
    code: data.code,
    uuid: data.uuid,
  }, {
    showLoading: true,
    showError: true,
  })
}

/**
 * 获取用户信息
 */
export function getUserInfo() {
  return request.get<UserInfoResponse>('/auth/getInfo')
}

/**
 * 获取路由信息
 */
export function getRouters() {
  return request.get('/auth/getRouters')
}

/**
 * 退出登录
 */
export function logout() {
  return request.post('/auth/logout', {}, {
    showLoading: true,
  })
}

/**
 * 获取验证码
 */
export function getCaptcha() {
  return request.get<CaptchaResponse>('/auth/captcha')
}

/**
 * 刷新token
 */
export function refreshToken() {
  return request.post('/auth/refresh')
}
